package huizhi.service.flower;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;

import java.util.List;

/**
 * TODO
 *
 * @author YuXD
 * @since 2023/12/18
 */
public class JDBC3 {

    public static void main(String[] args) {

        List<String> list = CollectionUtil.newArrayList("hello");
//
//        // SELECT custom_id,total_amount FROM bis_flower_order
//        System.out.println(query(null, null, null));
//        // SELECT custom_id,total_amount FROM bis_flower_order WHERE  base_id = '1111'
//        System.out.println(query("1704435229558108162", null, null));
//        // SELECT custom_id,total_amount FROM bis_flower_order
//        System.out.println(query(null, "2023-11-05", null));
//        // SELECT custom_id,total_amount FROM bis_flower_order
//        System.out.println(query(null, null, "2023-11-05"));
//        // SELECT custom_id,total_amount FROM bis_flower_order WHERE base_id = '1111' AND place_order_time BETWEEN  '开始时间' AND '结束时间'
//        System.out.println(query("1704435229558108162", "2023-11-05", "2023-11-05"));

        test("param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param","param");
    }

    public static void test(String... param1){

        for (int i = 0; i < param1.length; i++) {
            System.out.println(param1[i]);
        }

    }

    /**
     * 查询
     * 2023-11-05 08:06:28
     *
     * {}
     * {1}
     * ?
     * //s
     * ${param}
     *
     *
     * @param baseId
     * @param startDate yyyy-MM-dd 2
     * @param endDate   yyyy-MM-dd
     */
    public static String query(String baseId, String startDate, String endDate) {
        String rootSql = "SELECT custom_id,total_amount FROM bis_flower_order {} {}";
        List<String> queryCondition = CollectionUtil.newArrayList();
        // 如果基地不为空，需要拼接 base_id = '1111'  base_id = '{}'
        if (StrUtil.isNotEmpty(baseId)) {
            queryCondition.add(StrUtil.format("base_id = '{}'", baseId));
        }

        // place_order_time BETWEEN  '开始时间' AND '结束时间'
        // place_order_time BETWEEN  DATE_FORMAT('开始时间','%Y-%m-%d %H:%i:%s') AND DATE_FORMAT('开始时间','%Y-%m-%d %H:%i:%s')
        if (StrUtil.isAllNotEmpty(startDate, endDate)) {
            startDate += " 0:00:00";
            endDate += " 23:59:59";
            queryCondition.add(StrUtil.format("place_order_time BETWEEN DATE_FORMAT('{}','%Y-%m-%d %H:%i:%s') AND DATE_FORMAT('{}','%Y-%m-%d %H:%i:%s')", startDate, endDate));
        }
        if (CollectionUtil.isNotEmpty(queryCondition)) {
            rootSql = StrUtil.format(rootSql,"WHERE",CollectionUtil.join(queryCondition," AND "));
        }
        return rootSql;

    }

}
